from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render_to_response, get_object_or_404
from django.core.urlresolvers import reverse

from videosoft.apps.blog.models import *

def index(request):
	entries = Entry.objects.all().order_by('-creation_date')[:5]
#	output = ', '.join([p.name  for p in list])
#	return HttpResponse(output)
	return render_to_response('blog/index.html', {'entries': entries})

def entry(request, entry_id):
	e = get_object_or_404(Entry, pk=entry_id)
	return render_to_response('blog/entry.html', {'entry': e})

def comment(request, entry_id):
	e = get_object_or_404(Entry, pk=entry_id)
#	return render_to_response('blog/entry.html', {'entry': e})
#	return HttpResponse("Comment!!!")
#	try:
	c = Comment(content=request.POST['comment'], entry=e)
	c.save()
	return HttpResponseRedirect(reverse('videosoft.apps.blog.views.entry', args=(e.id,)))

#	except (KeyError):
#		# Redisplay the poll voting form.
#		return render_to_response('blog/error.html', {})
